package com.foxconn.ipebg.common.system.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import javax.servlet.http.HttpServletRequest;
import java.util.Locale;

/**
 * Created by H2012101 on 2015/12/5.
 */
@Controller
@RequestMapping("locale")
public class LocaleChangeController {
    @RequestMapping("change")
    public String localeChange(String langType,HttpServletRequest request){
        if(langType== null) langType ="";
        if (langType.equals("zh_CN")) {
            request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,new Locale("zh","CN"));
        }else if (langType.equals("en_US")) {
            request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,new Locale("en","US"));
        }else if (langType.equals("zh_TW")) {
            request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,new Locale("zh","TW"));
        } else {
            request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,new Locale("zh","CN"));
        }
        return "portal/welcome";
    }
}
